package leencode;

import org.junit.jupiter.api.Test;

public class no88_合并有序数组 {

    @Test
    public void test(){
        int[] ints = {4,0,0,0,0,0};
        merge(ints,1,new int[]{1,2,3,4,5},5);

        for (int i = 0; i < ints.length; i++) {
            System.out.println(ints[i]);
        }

    }

    // 1 2 3
    // 2 1 3
    // 1 2 3

    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int inx2 = 0;
        for (int i = 0; i < nums1.length; i++) {
            if (nums1[i] == 0){
                nums1[i] = nums2[inx2++];
            }
        }

        for (int i = 0; i < nums1.length; i++) {
            int j = i;
            for (; j < nums1.length; j++) {
                if (nums1[i] > nums1[j]){
                    int temp = nums1[i];
                    nums1[i] = nums1[j];
                    nums1[j] = temp;
                }
            }
        }

    }
}
